import {reqGetDetailInfo,reqAddOrUpdateShopCart} from '@/api'
import {getUUID} from '@/utils/uuid_token'
const state = {
    detailInfo:{},
    uuid_token:getUUID()
}
const mutations = {
    GETDETAILINFO(state,detailInfo){
        state.detailInfo = detailInfo
    }
} 
const actions = {
    async getDetailInfo({commit},skuId){
        let result = await reqGetDetailInfo(skuId);
        if(result.code === 200){
            commit('GETDETAILINFO',result.data)
        }
    },
    async addOrUpdateShopCart({commit},{skuId,skuNum}){
        let result = await reqAddOrUpdateShopCart(skuId,skuNum);
        if(result.code ===200){
            return 'ok'
        }else{
            return Promise.reject(new Error('error'))
        }
    }
}
const getters = {
    categoryView(state){
        return state.detailInfo.categoryView||{}
    },
    skuInfo(state){
        return state.detailInfo.skuInfo||{}
    },
    spuSaleAttrList(state){
        return state.detailInfo.spuSaleAttrList||[]
    }
}
export default {
    state,
    mutations,
    actions,
    getters
}